home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / doAttachCurveArgList.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  5.4 KB  |  197 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  April 17, 1997
  22. //  Author:        mgr 
  23. //
  24. //  Description:
  25. //      The doAttachCurveArgList() procedure executes an attach curve operation
  26. //      on a pair of curves based on the attach option vars. In general
  27. //        if you have n curves selected, only the last 2 curves would
  28. //        be attached.
  29. //
  30. //  Versions:
  31. //      "1" is Maya V1, Maya V1.5
  32. //      "2" is Maya V2.
  33. //
  34.  
  35. proc string pieceTogetherAttachCmd( string $version, string $args[] )
  36. //
  37. //    Description :
  38. //        Piece together an attach command.
  39. //
  40. {
  41.     string $cmd = "";
  42.     int $need = 0;
  43.  
  44.     if( "1" == $version ) {
  45.         $need = 3;
  46.     }
  47.     else if( "2" == $version ) {
  48.         $need = 7;
  49.     }
  50.     else {
  51.         warning( "Bad version for doAttachCurveArgList.  Using 1." );
  52.         $version = "1";
  53.         $need = 3;
  54.     }
  55.  
  56.     if( size($args) < $need ) {
  57.         error( "Not enough arguments to doAttachCurveArgList" );
  58.         return $cmd;
  59.     }
  60.  
  61.     $cmd = "attachCurve ";
  62.  
  63.     // construction history
  64.     $cmd = $cmd + " -ch " + $args[0];
  65.     $cmd = $cmd + " -rpo " + $args[1];
  66.     $cmd = $cmd + " -kmk " + $args[2];
  67.  
  68.     if( "2" == $version ) {
  69.         $cmd = $cmd + " -m " + $args[3];
  70.         $cmd = $cmd + " -bb " + $args[4];
  71.         $cmd = $cmd + " -bki " + $args[5];
  72.         $cmd = $cmd + " -p " + $args[6];
  73.     }
  74.  
  75.     return $cmd;
  76. }
  77.  
  78. global proc doAttachCurveArgList( string $version, string $args[] )
  79.  
  80. //
  81. //    attach with the preset options.
  82. //    Use this proc when operation dragged to Shelf.
  83. //
  84. {
  85.     string $cmd = pieceTogetherAttachCmd( $version, $args );
  86.     if( "" == $cmd ) return;
  87.  
  88.     int $history = $args[0];
  89.     int $replaceOriginal = $args[1];
  90.  
  91.     int $nitems = 2;
  92.     $cmd = appendToCmdPlaceHoldersForSelectionItems( $cmd, $nitems );
  93.  
  94.     // Get the list of nurbs curves selected.
  95.     //
  96.     global int $gSelectNurbsCurvesBit;
  97.     global int $gSelectCurvesOnSurfacesBit;
  98.     global int $gSelectCurveParmPointsBit;
  99.     string $curvesList[] = `filterExpand -ex true -sm $gSelectNurbsCurvesBit -sm $gSelectCurvesOnSurfacesBit -sm $gSelectCurveParmPointsBit`;
  100.  
  101.     int $numCurves = size($curvesList);
  102.     if ( $numCurves == 0 )
  103.     {
  104.         error("No curves selected to attach. You must select pairs of curves.");
  105.     }
  106.     else if ( $numCurves == 1 )
  107.     {
  108.         error("Not enough curves selected to attach. You must select pairs of curves.");
  109.     }
  110.     else if ( $numCurves > 1 )
  111.     {
  112.         // just use the last 2 selected curves
  113.         //
  114.         if ( $numCurves > 2 ) 
  115.             warning("Only 2 curves should be selected to attach. The last 2 selected curves will be used.");
  116.  
  117.         string $attachPair[2];
  118.         $attachPair[0] = $curvesList[$numCurves-2];
  119.         $attachPair[1] = $curvesList[$numCurves-1];
  120.  
  121.         if ( $history == 0 && $replaceOriginal == 1 )
  122.         {
  123.             // delete history on each input to attach cmd (so that command 
  124.             // won't force history on)
  125.             //
  126.             string $buffer[];
  127.             tokenize($attachPair[0], ".", $buffer);
  128.             string $curveName = $buffer[0];
  129.             $buffer = `listHistory -pdo 1 $curveName`;
  130.             if ( size($buffer) > 0 )
  131.             {
  132.                 // the first curve has history so delete it
  133.                 //
  134.                 warning("History will be deleted on first curve for attach.");
  135.                 evalEcho("delete -ch " + $curveName);
  136.             }
  137.  
  138.             tokenize($attachPair[1], ".", $buffer);
  139.             $curveName = $buffer[0];
  140.             $buffer = `listHistory -pdo 1 $curveName`;
  141.             if ( size($buffer) > 0 )
  142.             {
  143.                 // the second curve has history so delete it
  144.                 //
  145.                 warning("History will be deleted on second curve for attach.");
  146.                 evalEcho("delete -ch " + $curveName);
  147.             }
  148.         }
  149.  
  150.         string $results[] = executeCmdOnItems( $cmd, $attachPair );    
  151.  
  152.         // select the results.
  153.         //
  154.         int $resultCount = size($results);
  155.         if ( $resultCount > 0 ) 
  156.         {
  157.             string $selectString;
  158.             $selectString = "select ";
  159.             if ( $replaceOriginal )
  160.             {
  161.                 if ( $history == 0 )
  162.                 {
  163.                     // delete the second curve since it is no longer required
  164.                     evalEcho("delete " + $results[1]);
  165.                 }
  166.                 else
  167.                 {
  168.                     // make the second curve an intermediate object (so that
  169.                     // the user won't ever see it). Note: can't do "delete"
  170.                     // here or else attach result will go away due to history
  171.                     // on.
  172.                     //
  173.                     string $resultShapes[] = `listRelatives -s $results[1]`;
  174.                     int $shapeCount = size($resultShapes);
  175.                     if ( $shapeCount > 0 )
  176.                     {
  177.                         evalEcho("setAttr " + $resultShapes[0] + ".io true");
  178.                     }
  179.                 }
  180.                 $selectString +=  $results[0];
  181.             }
  182.             else
  183.             {
  184.                 int $i;
  185.                 for ( $i = 0; $i < $resultCount; $i++ ) 
  186.                 {
  187.                     $selectString +=  $results[$i];
  188.                     $selectString += " ";
  189.                 }
  190.             }
  191.             $selectString += ";";
  192.             select -cl;
  193.             eval($selectString);
  194.         }
  195.     }
  196. }
  197.